﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.门店出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.门店出入库
{
    public partial class Form其他返厂确认 : DevExpress.XtraEditors.XtraForm
    {
        public Form其他返厂确认()
        {
            InitializeComponent();
            this.刷新();
        }
        private void 刷新()
        {
            this.gridControl其他返厂确认.DataSource = 出入库Service.getAllOtherReturnIns();
            this.gridView其他返厂确认.RefreshData();
            this.gridView其他返厂确认.BestFitColumns();
            this.gridView其他返厂确认.ExpandAllGroups();
        }

        private void gridView其他返厂确认_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            try
            {
                if (e.Column.Name.Equals("gridColumn状态"))
                {
                    if ("确认".Equals(e.CellValue))
                    {
                        e.Appearance.BackColor = Color.LightPink;
                        e.Appearance.ForeColor = Color.White;
                    }
                    else if ("待确认".Equals(e.CellValue))
                    {
                        e.Appearance.BackColor = Color.MediumPurple;
                        e.Appearance.ForeColor = Color.White;
                    }
                    else if ("驳回".Equals(e.CellValue))
                    {
                        e.Appearance.BackColor = Color.OrangeRed;
                        e.Appearance.ForeColor = Color.White;
                    }
                }
            }
            catch { }
            try
            {
                if (e.Column.Name.Equals("gridColumn1"))
                {
                    if (3 >= Convert.ToInt32(e.CellValue))
                    {
                        e.Appearance.BackColor = Color.PaleVioletRed;
                        e.Appearance.ForeColor = Color.White;
                    }
                    else
                    {
                        e.Appearance.BackColor = Color.LightGreen;
                        e.Appearance.ForeColor = Color.White;
                    }
                }
            }
            catch { }
            try
            {
                if (e.Column.Name.Equals("gridColumn尺码"))
                {
                    if (!String.IsNullOrWhiteSpace(e.DisplayText))
                    {
                        try { e.DisplayText = e.DisplayText.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                    }
                }
            }
            catch { }
        }

        private void 确认ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String status = FunctionHelper.GetgridViewValue(this.gridView其他返厂确认, this.gridView其他返厂确认.FocusedRowHandle, "status");
            String id = FunctionHelper.GetgridViewValue(this.gridView其他返厂确认, this.gridView其他返厂确认.FocusedRowHandle, "id");
            try
            {
                if (String.IsNullOrWhiteSpace(status) || String.IsNullOrWhiteSpace(id))
                {
                    return;
                }
                if ("待确认".Equals(status))
                {
                    出入库Service.otherReturnInById(id);
                }
            }
            catch { }
            this.刷新();
        }

    }
}
